package Button;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import Base.Constantes;

public class buttonBase {
	private int x;
	private int y;
	private int widht;
	private int height;
	private boolean mouseOver;
	private boolean mouseClicked;
	private String text;
	private String telaPraSerCarregada;
	private BufferedImage backGround;
	private BufferedImage backGroundOver;
	
	

	public buttonBase(String Text, int posX, int posY, int Width, int Height, String telaPraSerCarregada) {
		// TODO Auto-generated constructor stub
		this.setText(Text);
		this.setMouseClicked(false);
		this.setMouseOver(false);
		this.setX(posX);
		this.setY(posY);
		this.setWidht(Width);
		this.setHeight(Height);
		this.setTelaPraSerCarregada(telaPraSerCarregada);
		
		
	}
	public buttonBase(int posX, int posY, int Width, int Height, String telaPraSerCarregada, String endImage, String endImageOver) {
		// TODO Auto-generated constructor stub
	
		this.setMouseClicked(false);
		this.setMouseOver(false);
		this.setX(posX);
		this.setY(posY);
		this.setWidht(Width);
		this.setHeight(Height);
		this.setTelaPraSerCarregada(telaPraSerCarregada);
		this.setBackGround(Constantes.LoadImage(endImage));
		this.setBackGroundOver(Constantes.LoadImage(endImageOver));
		
	}
	
	public void Draw(Graphics2D dbg){
		if(getBackGround()!=null){
			if(isMouseOver()){
				dbg.drawImage(getBackGroundOver(), getX(), getY(),null);
			}else{			
				dbg.drawImage(getBackGround(), getX(), getY(),null);
			}			
		}else{
			//System.out.println("passou no botao pra desenhar");
			dbg.setColor(Color.RED);
			dbg.fillRect(getX(),getY(), getWidht(), getHeight());
			dbg.setColor(Color.BLACK);	
			dbg.drawString(getText(), getX(), getY()+14);
		}
	}
	
	
	public void Update(long diffTime){
		
	}
	
	public void setX(int x) {
		this.x = x;
	}
	
	public int getX() {
		return x;
	}



	public void setY(int y) {
		this.y = y;
	}

	public int getY() {
		return y;
	}



	public void setWidht(int widht) {
		this.widht = widht;
	}

	public int getWidht() {
		return widht;
	}



	public void setHeight(int height) {
		this.height = height;
	}



	public int getHeight() {
		return height;
	}



	public void setMouseOver(boolean mouseOver) {
		this.mouseOver = mouseOver;
	}



	public boolean isMouseOver() {
		return mouseOver;
	}



	public void setMouseClicked(boolean mouseClicked) {
		this.mouseClicked = mouseClicked;
	}



	public boolean isMouseClicked() {
		return mouseClicked;
	}



	public void setText(String text) {
		this.text = text;
	}



	public String getText() {
		return text;
	}



	public void setTelaPraSerCarregada(String telaPraSerCarregada) {
		this.telaPraSerCarregada = telaPraSerCarregada;
	}

	public String getTelaPraSerCarregada() {
		return telaPraSerCarregada;
	}

	public void setBackGround(BufferedImage backGround) {
		this.backGround = backGround;
	}
	
	public BufferedImage getBackGround() {
		return backGround;
	}
	
	/*
	 * testa pra saber se o ponteiro so mouse esta em cima do botao;
	 */
	public void mouseOver(int mouseX, int mouseY) {
		// TODO Auto-generated method stub		
		this.setMouseOver(Constantes.ColisaoRetangular(mouseX, mouseY, mouseX, mouseY, this.getX(), this.getY(), this.getFinalX(), this.getFinalY()));
		
	}
	/*
	 * pega a posicao final X que esta sendo desenhado
	 */
	public int getFinalX() {
		// TODO Auto-generated method stub
		return getX()+getWidht();
	}
	/*
	 * pega a posicao final Y que esta sendo desenhado
	 */
	public int getFinalY(){
		return getY()+getHeight();
	}
	
	public void setBackGroundOver(BufferedImage backGroundOver) {
		this.backGroundOver = backGroundOver;
	}
	
	public BufferedImage getBackGroundOver() {
		return backGroundOver;
	}
	
	public void testClick() {
		// TODO Auto-generated method stub
		if(isMouseOver()){
			System.out.println("true");
			setMouseClicked(true);
		}else{
			setMouseClicked(false);
		}
		
	}

}
